package com.medium.house.utils.excel;


import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Workbook;

public class ExcelStype {

    public static CellStyle priceStyle = null;
    public static CellStyle numberStyle = null;
    public static CellStyle strStyle = null;

    public static CellStyle getTitleStyle(Workbook wb) {
        priceStyle = null;
        numberStyle = null;
        strStyle = null;
        Font titleFont = wb.createFont();
        titleFont.setBoldweight((short) 700);
        titleFont.setFontHeight((short) 380);
        CellStyle cellStyle = wb.createCellStyle();
        cellStyle.setFont(titleFont);
        cellStyle.setAlignment(CellStyle.VERTICAL_CENTER);
        cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        cellStyle.setWrapText(true);
        return cellStyle;
    }

    public static CellStyle getPriceStyle(Workbook wb) {
        if (ExcelStype.priceStyle == null) {
            ExcelStype.priceStyle = wb.createCellStyle();
            ExcelStype.priceStyle.setDataFormat(wb.createDataFormat().getFormat("0.00"));
            ExcelStype.priceStyle.setAlignment(CellStyle.ALIGN_RIGHT);
            // ## 设置底部边框为THIN ##//
            ExcelStype.priceStyle.setBorderBottom(CellStyle.BORDER_THIN);
            // ## 设置底部边框颜色为黑色 ##//
            ExcelStype.priceStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
            // ## 设置左边边框为THIN ##//
            ExcelStype.priceStyle.setBorderLeft(CellStyle.BORDER_THIN);
            // ## 设置左边边框颜色为红色 ##//
            ExcelStype.priceStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
            // ## 设置右边边框为THIN ##//
            ExcelStype.priceStyle.setBorderRight(CellStyle.BORDER_THIN);
            // ## 设置右边边框颜色为蓝色 ##//
            ExcelStype.priceStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
            // ## 设置顶部边框为MEDIUM DASHED ##//
        }
        return ExcelStype.priceStyle;
    }

    public static CellStyle getNumberStyle(Workbook wb) {
        if (ExcelStype.numberStyle == null) {
            ExcelStype.numberStyle = wb.createCellStyle();
            ExcelStype.numberStyle.setAlignment(CellStyle.ALIGN_RIGHT);
            // ## 设置底部边框为THIN ##//
            ExcelStype.numberStyle.setBorderBottom(CellStyle.BORDER_THIN);
            // ## 设置底部边框颜色为黑色 ##//
            ExcelStype.numberStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
            // ## 设置左边边框为THIN ##//
            ExcelStype.numberStyle.setBorderLeft(CellStyle.BORDER_THIN);
            // ## 设置左边边框颜色为红色 ##//
            ExcelStype.numberStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
            // ## 设置右边边框为THIN ##//
            ExcelStype.numberStyle.setBorderRight(CellStyle.BORDER_THIN);
            // ## 设置右边边框颜色为蓝色 ##//
            ExcelStype.numberStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
            // ## 设置顶部边框为MEDIUM DASHED ##//
        }
        return ExcelStype.numberStyle;
    }

    public static CellStyle getStrStyle(Workbook wb) {
        if (ExcelStype.strStyle == null) {
            ExcelStype.strStyle = wb.createCellStyle();
            ExcelStype.strStyle.setWrapText(true);//设置自动换行
            ExcelStype.strStyle.setAlignment(CellStyle.VERTICAL_CENTER);
            ExcelStype.strStyle.setAlignment(CellStyle.ALIGN_CENTER);
            // ## 设置底部边框为THIN ##//
            ExcelStype.strStyle.setBorderBottom(CellStyle.BORDER_THIN);
            // ## 设置底部边框颜色为黑色 ##//
            ExcelStype.strStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
            // ## 设置左边边框为THIN ##//
            ExcelStype.strStyle.setBorderLeft(CellStyle.BORDER_THIN);
            // ## 设置左边边框颜色为红色 ##//
            ExcelStype.strStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
            // ## 设置右边边框为THIN ##//
            ExcelStype.strStyle.setBorderRight(CellStyle.BORDER_THIN);
            // ## 设置右边边框颜色为蓝色 ##//
            ExcelStype.strStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
            // ## 设置顶部边框为MEDIUM DASHED ##//
        }
        return ExcelStype.strStyle;
    }

    public static CellStyle getHeaderStyle(Workbook wb) {
        Font headerFont = wb.createFont();
        headerFont.setBoldweight((short) 700);

        CellStyle cellStyle = wb.createCellStyle();
        cellStyle.setFont(headerFont);
        cellStyle.setWrapText(true);
        cellStyle.setAlignment(CellStyle.VERTICAL_CENTER);
        cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        // ## 设置底部边框为THIN ##//
        cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
        // ## 设置底部边框颜色为黑色 ##//  
        cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        // ## 设置左边边框为THIN ##//  
        cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
        // ## 设置左边边框颜色为红色 ##//  
        cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        // ## 设置右边边框为THIN ##//  
        cellStyle.setBorderRight(CellStyle.BORDER_THIN);
        // ## 设置右边边框颜色为蓝色 ##//  
        cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
        // ## 设置顶部边框为MEDIUM DASHED ##//  
        return cellStyle;
    }

    public static CellStyle getTotalStyle(Workbook wb) {
        Font headerFont = wb.createFont();
        headerFont.setBoldweight((short) 700);
        headerFont.setColor((short) 400);
        CellStyle cellStyle = wb.createCellStyle();
        cellStyle.setAlignment(CellStyle.VERTICAL_CENTER);
        cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        cellStyle.setFont(headerFont);
        return cellStyle;
    }
}
